package com.gitee.feizns.quickstart.ding.talk.api.top.api.role;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleDeleteroleRequest;
import com.dingtalk.api.response.OapiRoleDeleteroleResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 删除角色（/topapi/role/deleterole）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/add-role">删除角色（/topapi/role/deleterole）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/add-role">服务端API > 通讯录管理 > 角色管理 > 删除角色</a>
 * @author feizns
 * @since 2024/7/28
 */
public class DeleteRole {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param roleId 角色编号
     * @return {@link Long }
     */
    @SneakyThrows
    public static String execute(String accessToken, Long roleId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/deleterole");
        OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
        req.setRoleId(roleId);
        OapiRoleDeleteroleResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getBody();
    }

}
